<?php

namespace App\Http\Controllers\Api;

use App\Models\Brand;
use App\Models\Banner;
use App\Models\Copyright;
use App\Models\MiniProgramInfo;
use App\Models\MiniProgramModuleSetting;

class IndexController extends ApiController
{
    /**
     * $app = app('wechat.mini_program');
     * @return mixed
     */
    public function appLaunch()
    {
        //小程序信息
        $miniprograminfo = MiniProgramInfo::select('appid', 'title', 'sub_title', 'profile', 'share_title', 'share_pic','bg_img', 'service_phone', 'service_time','about_us')->first();
        $data['miniprograminfo'] = $miniprograminfo;
        $data['copyright'] = Copyright::where('is_show', 1)->first();
        return $this->success($data);
    }
    public function about()
    {
        //小程序信息
        $miniprograminfo = MiniProgramInfo::select('about_us')->first();
        $data['about'] = $miniprograminfo->about_us;
        return $this->success($data);
    }
    public function index()
    {

        $recommend_module = MiniProgramModuleSetting::where('module_name', 'recommend_module')->first();
        $newproduct_module = MiniProgramModuleSetting::where('module_name', 'newproduct_module')->first();
        $hotproduct_module = MiniProgramModuleSetting::where('module_name', 'hotproduct_module')->first();
        $video_module = MiniProgramModuleSetting::where('module_name', 'video_module')->first();
        $if_show_recommend = !empty($recommend_module)? $recommend_module->is_show:false;
        $if_show_newproduct = !empty($newproduct_module)? $newproduct_module->is_show:false;
        $if_show_hotproduct = !empty($hotproduct_module) ? $hotproduct_module->is_show:false;
        $if_show_video = !empty($video_module)? $video_module->is_show:false;
        $data['if_show_recommend'] = $if_show_recommend;
        $data['if_show_newproduct'] = $if_show_newproduct;
        $data['if_show_hotproduct'] = $if_show_hotproduct;
        $data['if_show_video'] = $if_show_video;
        if ($if_show_newproduct) {
            $data['newproduct_module_pic'] = $newproduct_module->pic;
        }
        if ($if_show_video) {
            $data['video_src'] = $video_module->video_src;
        }

        $banners = Banner::get();
        $brands = Brand::get();
        $data['banners'] = $banners;
        $data['brands'] = $brands;
        return $this->success($data);
    }

}
